package cn.tedu.basic;
//测试File
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) throws IOException {
        Method();
        Method1();
        Method2();
    }
    //统计文件夹里文件的总大小
    public static void Method(){
        File f =new File("D:\\zhang");
        File f1[]=f.listFiles();
        long a =0;
        for (int i = 0; i <f1.length ; i++) {
            File f2=f1[i];
            if (f2.isFile()) {
                 a = f2.length()+a;
            }
        }
        System.out.println(a);
    }
    //统计文件夹里文件总大小
    public static void Method1(){
        File fi =new File("D\\you");
        File fi1[] =fi.listFiles();
        long b=0;
        for (int i = 0; i <fi1.length ; i++) {
            File fi2=fi1[i];
            if (fi2.isFile()){
                b=fi2.length()+b;
            }
        }
        System.out.println(b);
    }
    public static void Method2() throws IOException {
        File fe =new File("D\\zhang");
        File fe1[] =fe.listFiles();
        long l =0;
        for (int i = 0; i <fe1.length ; i++) {
            File fe2=fe1[i];
            if (fe2.isFile()){
                l =fe2.length()+l;
            }
        }
        System.out.println(l);
    }
    public static long Method3(File wjj) throws IOException {
        System.out.println("请输入文件夹路径:");
        String dirpath=new Scanner(System.in).nextLine();
        File dir =new File(dirpath);
        long total =Method3(dir);
        System.out.println(total);
        File fe3[]=wjj.listFiles();
        long lg =0;
        for (int i = 0; i <fe3.length ; i++) {
            File fe4=fe3[i];
            if (fe4.isFile()){
                lg=fe4.length()+lg;
            }else if (fe4.isDirectory()){
               lg= lg + Method3(fe4);
            }
        }
        System.out.println("文件夹路径是:"+wjj.getCanonicalPath()+"总大小是:"+lg);
        return total;
    }

}
